package com.unionbigdata.teaching.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.unionbigdata.teaching.common.Result;
import com.unionbigdata.teaching.entity.ServiceEntity;
import com.unionbigdata.teaching.sevice.ServiceService;
import com.unionbigdata.teaching.vo.req.ServicePageReq;
import com.unionbigdata.teaching.vo.resp.ServiceEntityRespVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/service")
@Tag(name = "服务信息")
public class ServiceController {
    @Resource
    private ServiceService serviceService;

    @Operation(summary = "根据Id查询服务信息")
    @GetMapping("/{id}")
    public Result<ServiceEntityRespVO> findById(@PathVariable Long id) {
        return Result.ok(serviceService.getById(id));
    }

    @Operation(summary = "根据Id删除服务信息")
    @DeleteMapping("/delete/{id}")
    public Result<Boolean> deleteById(@PathVariable Long id) {
        return Result.ok(serviceService.removeById(id));
    }

    @Operation(summary = "批量删除Ids删除服务信息")
    @DeleteMapping("/delete")
    public Result<Boolean> deleteByIds(@RequestBody List<Long> ids) {
        return Result.ok(serviceService.removeByIds(ids));
    }

    @Operation(summary = "根据Id查询服务信息")
    @PutMapping("/update")
    public Result<Boolean> update(@RequestBody ServiceEntity serviceEntity) {
        return Result.ok(serviceService.updateById(serviceEntity));
    }

    @Operation(summary = "根据Id查询服务信息")
    @PostMapping("/page")
    public Result<Page<ServiceEntityRespVO>> page(@RequestBody ServicePageReq req) {
        return Result.ok(serviceService.page(req));
    }

    @Operation(summary = "新增服务信息")
    @PostMapping("/add")
    public Result<Boolean> add(@RequestBody ServiceEntity req) {
        return Result.ok(serviceService.save(req));
    }
}
